import warnings
warnings.warn("qturboframe.public_ui.ufc_wpf.message模块已被废弃，替代模块为qturboframe.public_ui.ucf_wpf.message", DeprecationWarning)

from qturboframe.lib.ranorex.exceptions import CsClientError
from qturboframe.lib.report.log import logger
from qturboframe.public_ui.ufc_wpf.basecontrol import BaseControl
from qturboframe.lib.ranorex.win_control.text import Text as WinText
from qturboframe.lib.ranorex.win_control.button import Button as WinButton

from qturboframe.public_ui.ufc_wpf.button import Button
from qturboframe.public_ui.ufc_wpf.radio_button import RadioButton


class Message(BaseControl):
    '''ucf的输入框'''

    def __init__(self, element_para, father=None, timeout=10000):
        super().__init__(element_para, father, timeout)

    def get_message(self):
        '''
        ucf文本框填充

        :Args:
         - text: 填充值

        :Example:
         - 例: input_type.set_value('admin')
        '''
        text = self._element.exist("xpath",".//text", timeout=1000)
        if text:
            text_control = WinText(text.control)
            return text_control.get_text()
        else:
            raise CsClientError("在弹出的信息窗口上没有找到文本控件")

    def get_button(self, text):
        assist = "text:{}".format(text)
        button = self._element.exist("xpath",".//button", assist=assist, timeout=1000)
        if button:
            return Button(button, self._driver, self.timeout)
        raise CsClientError('没有找到标签为:“{}”的控件'.format(text))
    
    def confirm(self, text='确定'):
        logger.info("点击确定按钮")
        self.get_button(text=text).click()
    
    def cancel(self, text='取消'):
        logger.info("点击取消按钮")
        self.get_button(text=text).click()

    def get_radio(self, text):
        assist = "text:{}".format(text)
        #获取标记radio的label控件
        radio = self._element.exist("xpath",".//text[@Type='Label']", assist=assist, timeout=1000)
        if radio:
            return RadioButton(radio, self._driver, self.timeout)

        radio = self._element.exist("xpath",".//text[@Type='TextBlock']", assist=assist, timeout=1000)
        if radio:
            return RadioButton(radio, self._driver, self.timeout)
        raise CsClientError('没有找到标签为:“{}”的控件'.format(text))